package com.dc.commons.shiro.session;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.SessionFactory;
import org.apache.shiro.web.session.mgt.WebSessionContext;

public class DcSessionFactory implements SessionFactory {

	@Override
	public Session createSession(SessionContext initData) {
		final DcSession session=new DcSession();
		if(initData instanceof WebSessionContext){
			WebSessionContext sessionContext=(WebSessionContext)initData;
			HttpServletRequest request=(HttpServletRequest)sessionContext.getServletRequest();
			if(request!=null){
				session.setUserAgent(request.getHeader("User-Agent"));
			}
		}
		
		return session;
	}

}
